-- https://github.com/nvim-pack/nvim-spectre
-- WARN: spectre 手动安装依赖项 sed 和 ripgrep
-- sed 命令（自行安装，如果已有则忽略）
-- repgrep： https://github.com/BurntSushi/ripgrep
local status_ok, spectre = pcall(require, "spectre")
if not status_ok then
  vim.notify("spectre not found!")
  return
end

spectre.setup(
  {
    mapping = {
      -- 取消选中
      ["toggle_line"] = {
        map = "dd",
        cmd = "<cmd>lua require('spectre').toggle_line()<CR>",
        desc = "toggle current item"
      },
      -- 前往文件
      ["enter_file"] = {
        map = "o",
        cmd = "<cmd>lua require('spectre.actions').select_entry()<CR>",
        desc = "goto current file"
      },
      -- 查看菜单（忽略大小写、忽略隐藏文件）
      ["show_option_menu"] = {
        map = "<leader>o",
        cmd = "<cmd>lua require('spectre').show_options()<CR>",
        desc = "show option"
      },
      -- 开始替换
      ["run_replace"] = {
        map = "<leader>r",
        cmd = "<cmd>lua require('spectre.actions').run_replace()<CR>",
        desc = "replace all"
      },
      -- 显示差异
      ["change_view_mode"] = {
        map = "<leader>v",
        cmd = "<cmd>lua require('spectre').change_view()<CR>",
        desc = "change result view mode"
      }
    }
  }
)
